﻿/*
 * Created by SharpDevelop.
 * User: mac
 * Date: 20.07.2006
 * Time: 18:32
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

namespace TagTool.GraphicTypes
{
	[Serializable()]
	public class Range
	{
		double minimum;
		double maximum;
		
		public Range()
		{
		}
		
		public Range(double value)
		{
			this.minimum = value;
			this.maximum = value;
		}
		
		public bool IsInside(double value)
		{
			return (value <= maximum && value >= minimum);
		}
		
		public Range(double minimum, double maximum)
		{
			this.minimum = minimum;
			this.maximum = maximum;
		}
		
		public double Minimum
		{
			get { return minimum; }
			set { minimum = value; }
		}
		
		public double Maximum
		{
			get { return maximum; }
			set { maximum = value; }
		}
		
		public static Range Parse(String description)
		{
			String [] p = description.Split('-');
			if (p.Length > 1)
			{
				return new Range(Convert.ToDouble(p[0]), Convert.ToDouble(p[1]));
			}
			else
			{
				return new Range(Convert.ToDouble(p[0]));
			}
		}
		
		public override string ToString()
		{
			if (minimum == maximum)
			{
				return minimum.ToString();
			}
			else
			{
				return String.Format("{0}-{1}", minimum, maximum);
			}
		}
	}
}
